package com.njcs.treeset;

import java.util.HashSet;

/**
 * @author Sam.Lee
 * @version Created：Feb 6, 2012 5:03:32 PM
 */
public class TreeSet1 {
	public static void main(String[] args) {
		HashSet<Student> hs = new HashSet<Student>();
		Student st1 = new Student(1, "zhao");
		Student st2 = new Student(2, "qian");
		Student st3 = new Student(3, "sun");
		hs.add(st1);
		hs.add(st2);
		hs.add(st3);
		System.out.println(hs);
		st1.num = 4; // 可以试着注释掉这一行看一看结果
		hs.remove(st1);
		System.out.println(hs);
	}
}

class Student {
	int num;
	String name;

	public Student(int num, String name) {
		this.num = num;
		this.name = name;
	}

	public int hashCode() {
		return new Integer(num).hashCode();
	}

	@Override
	public boolean equals(Object st) {
		Student tempStudent = (Student) st;
		if (num == tempStudent.num)
			return true;
		else
			return false;
	}

	public String toString() {
		return "student " + num + " name:" + name;
	}

}